﻿/*
*   学员信息页面
*/
angular.module('jisuStuHome')
.controller('myfollowexpertController', ['$scope', '$rootScope', '$state', 'StuRequestTrain', 'interlocutionservice', 'sysUserInfo', 'Msg', 'T', 'LS', function ($scope, $rootScope, $state, ST, IS, sysUserInfo, Msg, T, LS) {

    //初始
    $scope.init = function () {
        $rootScope.parstr = "home.interlocution";
        $rootScope.twoparstr = "home.interlocution.myfollowexpert";
        $scope.searchTxt = "";
        $scope.knowledgeid = "";
        //查询关注的专家的参数
        $scope.params = {
            userid: sysUserInfo.getuserinfo().user_ID,
            searchTxt: "",
            orgid: sysUserInfo.getuserinfo().organization_ID,
            type: 2,
            pageIndex: 1,
            pageSize: 10
        };
    }
    //返回主页，专栏列表
    $scope.backHome = function () {
        $rootScope.twoparstr = "home.interlocution";
        $rootScope.parstr = "home.interlocution";
        $state.go($rootScope.twoparstr);
    }
    //路由跳转专家动态
    $scope.openExpert = function (item) {
        $rootScope.twoparstr = "home.interlocution.expertdynamic";
        LS.setLS(sysUserInfo.getuserinfo().user_ID + '_expert', item);
        $state.go($rootScope.twoparstr);
    }
    //搜索
    $scope.searchByTxt = function () {
          $scope.getList(); //我关注的专栏
    }

    
    /**********************************专家***********************************/
      $scope.getList = function () {
        IS.findExpert($scope.params).then(function (response) {
            $scope.Loading = false;
            if (response.errorcode == "0") {
                $scope.followExpert = response.datas; //我关注的专家
                $scope.paginationConf.totalItems = response.numCount;
                $scope.paginationConf.currentPage = response.pageIndex;
            } else {
                Msg.error("查询异常!")
            }
        }, function errorCallback() {
            $scope.Loading = false;
            console.log("连接服务器失败！");
        });
    }
    //取消或新增关注（专家）
    $scope.abolishConcern = function (item) {
        $scope.Loading = true;
        var param = { expertId: item.expertId, expertUserId: item.userId, userId: sysUserInfo.getuserinfo().user_ID };
        IS.addFollow(param).then(function (response) {
            if (response.errorcode == "0") {
                Msg.success("操作成功！");
                $rootScope.TJInfo.followzjNum = $rootScope.TJInfo.followzjNum - 1; //修改收藏专家数量
                $scope.getList();
            } else {
                Msg.error("操作异常!")
            }
            $scope.Loading = false;
        }, function errorCallback() {
            $scope.Loading = false;
            console.log("连接服务器失败！");
        });
    }
    /*********************************************************************/
    //配置分页
    $scope.paginationConf = {
        currentPage: 1, //$location.search().currentPage ? $location.search().currentPage :  当前页码
        totalItems: 0,  // 总的记录数
        itemsPerPage: 10, // 每页显示多少条        
        perPageOptions: [10, 20],   // 每页显示记录数        
        onChange: function () {
            $scope.paginationConf.currentPage = $scope.paginationConf.currentPage == 0 ? 1 : $scope.paginationConf.currentPage;
            $scope.params.pageIndex = $scope.paginationConf.currentPage;
            $scope.params.pageSize = $scope.paginationConf.itemsPerPage;
            $scope.getList();
        }
    };
    /***********************************************初始*****************************************************/
    //初始
    $scope.init();
} ]);




